<?php
namespace Hong\Webdav;

trait TraitOptions
{
    /**
	 * 获取服务器支持的WebDAV功能 (OPTIONS)
	 * @return array 服务器支持的功能列表
	 * @throws \RuntimeException 当请求失败时抛出异常
	 */
	public function options()
	{
		if ($this->serverCapabilities !== null) {
			return $this->serverCapabilities;
		}

		$response = $this->sendRequest('OPTIONS', '');

		if ($response['status'] !== 200) {
			throw new \RuntimeException("Failed to get server options. Status: " . $response['status']);
		}

		$this->serverCapabilities = [
			'dav' => explode(',', $response['headers']['dav'] ?? ''),
			'allow' => explode(',', $response['headers']['allow'] ?? ''),
			'server' => $response['headers']['server'] ?? ''
		];

		return $this->serverCapabilities;
	}
}